package com.jjsc.product.api.factory;

import com.jjsc.common.core.domain.R;
import com.jjsc.product.api.RemoteProductService;
import com.jjsc.product.api.domain.Product;
import com.jjsc.product.api.domain.ProductSku;
import com.jjsc.product.api.domain.skuPriceVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.List;

/**
 * @Author: 钟城明
 * @CreateTime: 2025-10-06
 * @Description:
 * @Version: 1.0
 */
public class ProductFeignFallback implements FallbackFactory<RemoteProductService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteProductService.class);

    @Override
    public RemoteProductService create(Throwable cause) {
        log.error("获取商品SKU失败:{}", cause.getMessage());
        return new RemoteProductService() {
            @Override
            public R<ProductSku> getProductSku(Long skuId, String source) {
                return R.fail("获取商品SKU详情失败: " + cause.getMessage());
            }

            @Override
            public R<skuPriceVo> getSkuPrice(Long skuId, String source) {
                return R.fail("获取商品价格失败: " + cause.getMessage());
            }

            @Override
            public R<List<skuPriceVo>> getSkuPriceList(List<Long> skuIdList, String source) {
                return R.fail("批量获取商品价格失败: " + cause.getMessage());
            }
        };

    }
}
